/*
	读取表头配置，写入查询缺省表头
*/
#pragma once
//#include "structdef.h"
#include "Msg/ArrayListMsg.h"
#include <map>
#include <QObject>
#include <QSettings>
#include <memory>
//#include "View/Component/pair.h"

struct ColumnItem 
{
	QString name;
	QString ID;
	int		align;
	int		show;
	int		index;
	QString	fmt;	//
	QString	fmtExtra;	//fmt参数
};
class CFormatData;
class ColumnListModel;
class CColumnConfig : public QObject
{
	Q_OBJECT

public:
	CColumnConfig();
	~CColumnConfig();
	//读取配置表头信息,只读可见的
	//vector<stColumnInfo> GetColumnInfo(const string& sListName);
	//读取配置表头信息
//	map<int, stColumnInfo>	GetAllColumnInfo(const string& sListName);
	//修改表头设置
//	void ModifyColumnInfo(const string& sListName, const map<int, stColumnInfo> mapCols);

	//写配置文件

	Q_INVOKABLE QList<QString> getRoleNames(QString qsSection);
    void GetRoleNames(const QString qsSection,QHash<int,QByteArray>& roleNames,QStringList& dIndex);
	Q_INVOKABLE QList<int> getColumnWidths(QString qsSection);
	Q_INVOKABLE QList<int> getColumnAligns(QString qsSection);
	Q_INVOKABLE QList<QString> getTitles(QString qsSection);
	//配置显示列---model
	Q_INVOKABLE ColumnListModel* getColumnModel(QString qsListName);

	//保存
	Q_INVOKABLE void saveColumnCfg(QString qsSection,ColumnListModel* pModel);

    //设置列宽
    Q_INVOKABLE void setColumnWidth(QString qsSection, QString qsRole, int nWidth);
    Q_INVOKABLE void saveColumnWidth();
signals:
    void saveColumn(QString qsSetion);
protected:

private:
    QString m_sCfgFullName;
    std::shared_ptr<QSettings> m_gridInfo;
    QMap<QString, QMap<QString,int>>    m_mapWidth;
};

#include <QAbstractListModel>
class ColumnListModel : public QAbstractListModel
{
	Q_OBJECT
public:
	ColumnListModel();
	~ColumnListModel();

	Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
	Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
	virtual QHash<int, QByteArray> roleNames() const;

	QList<ColumnItem> GetData();
	//添加一个
	Q_INVOKABLE int addData(ColumnItem it);

	Q_INVOKABLE void moveUp(int nFocus);
	Q_INVOKABLE void moveDown(int nFocus);

	Q_INVOKABLE void setCheck(int nFocus, bool bCheck);	// show
	Q_INVOKABLE void setName(int nFocus, QString name);		//name
	Q_INVOKABLE void setEnName(int nFocus, QString name);	//ID
	//参数2：
	Q_INVOKABLE void setAlign(int nFocus, int nAlign);	//align
	//
	Q_INVOKABLE void setFmt(int nFocus, QString name);	//ID
	Q_INVOKABLE void setFmtExtra(int nFocus, QString name);	//ID
	Q_INVOKABLE void insertRow();
private:

	//
	QHash<int, QByteArray> m_roleNames;
	QList<ColumnItem> m_vData;
	//QList<Pair*> m_vTempData;   //临时
	//增加一个map，存放m_vData一样的指针，用于更新数据
	//   map<Inst,QuoData*> m_mapData;
	int     m_nColumns; //一行可容纳的block个数
	//    map<QModelIndex, QuData*>  m_modeData;
};

